<?php 
$this->load->view('header', $template);
?>
<link rel="stylesheet" href="<?php echo base_url() ?>assets/css/reading.css">
<!-- ---------------------------------------------------------- -->


<?php if(isset($edittag) && $edittag == true) { ?>
<div class="popup-control">
	<h2>GHI CHÚ</h2>
	<form id="tag-form" name="tag-form" action="">
		<span>Nội dung: </span>
		<input type="text" placeholder="" class="text">
		<br />

		<span>Địa điểm: <input type="checkbox" class="is-location"></span> <br/>
		<div class="location">
			<select name="local">
				<option value="null">Không chọn</option>
				<?php 
				foreach ($location_lv_1 as $city) {
				 	echo '<option value="'.$city['id_location'].'">'
				 	.$city['type_location'].' '.$city['name_location']
				 	.'</option>';
				 } 
				 ?>				
			</select>
		</div> <br />

		<input type="submit" class="submit" value="thêm">
	</form>
</div>
<?php } ?>

<section class="content-section">
	<div class="wrapper content" style="padding-top: 30px; padding-bottom: 45px;">
		<?php 
		if($error == false) 
			foreach($content as $el) {
				echo $el->asXML();
			} 
		else echo '<h2>Chương này không tồn tại</2>'
		?> 
		
	</div>
</section>

<div class="but" style="position: fixed; top: 150px; right: 10px; background: #fff;">
	Go to Tag
</div>

<?php if(!isset($action) || $action != 'removetag') { ?>
<section class="control-panel">

	<a class="to-prev" 
		href="<?php echo base_url().'book/read/'.$bookId.'/'.$prev_chapter; ?>" title="">
		<i class="fa fa-angle-left"></i>
	</a>

	<a class="info"
		href="<?php echo base_url().'book/info/'.$bookId ?>" title="">
		<i class="fa fa-book"></i>
	</a>

	<a class="to-next"
		href="<?php echo base_url().'book/read/'.$bookId.'/'.$next_chapter; ?>" title="">
		<i class="fa fa-angle-right"></i>
	</a>
</section>
<?php } ?>

<?php if(isset($action) && $action == 'removetag') { ?>
	<script>
		$(document).ready(function() {
			$(".<?php echo $tagid; ?>").each(function() {
				$(this).replaceWith(this.childNodes);
			});

			modifyBook();



		});

		// Call ajax to modify in XHTML File
		modifyBook = function() 
		{
			var content = $('section .wrapper.content').html();
			$.ajax({
				type: "POST",
				url: '/openlibraryonline/book/book_modify/',
				data: ({
					link: link_chap,
					content: content.toString(),
				}),
				success: function(data) {
					$(".result .wrapper").html(data);
					console.log(data);
					alert('Xóa gợi ý thành công') ;
					 window.location = "<?php echo base_url() ?>user";
				}
			});
		}

	</script>
<?php } ?>

	<script>
		$(document).ready(function() {
			path = document.URL;
			// strPath = path.toString();
			tag_index = path.toString().search("tag=");
			tagid = path.substring(tag_index + 4);

			if(tag_index != -1) {
				var x = $('.'+tagid).offset().top - 100;
				// alert(x);

				// $.ajax

				$('.'+tagid).addClass('echoTag');
				$('span.echoTag').append('<span class="content">Gợi ý: <?php echo $tag["name_tags"]; ?></span>');

				$('html, body').animate({
				    scrollTop: x
				});
				$('.but').click(function() {
					$('html, body').animate({
					    scrollTop: x
					});
				});
				
			}
			// alert(tagid);
		});
	</script>

<script type="text/javascript"> 
	var link_chap = '<?php echo $link_to_chapter; ?>';
	var book_id = '<?php echo $bookId; ?>';
	var chap_id = '<?php echo $chapId; ?>';
</script>
<script type="text/javascript" src="<?php echo base_url() ?>/assets/js/readbook.js">
</script>
	

<!-- ---------------------------------------------------------- -->	
	
<?php
/** Load Footer
*/
$this->load->view('footer');
?>